<template>
	<view>
		<zy-empty v-if="formList.length==0"></zy-empty>
		<view v-for="(item, index) in formList" :key="item.id" v-else>
			<zy-group :title="$t('public.callTime')+$t('public.colon') + item.createTime" :btnList="btnList"
				@btnHandle="btnHandle(item, index)" model="card">
				<view class="content">
					<text class="title">{{$t('homepage.CallDeal.department')}}{{$t('public.colon')}}</text>
					<view class="text">{{item.department}}</view>
				</view>
				<view class="content">
					<text class="title">{{$t('homepage.CallDeal.group')}}{{$t('public.colon')}}</text>
					<view class="text">{{item.title}}</view>
				</view>
				<view class="content">
					<text class="title">{{$t('homepage.CallDeal.callType')}}{{$t('public.colon')}}</text>
					<view class="text">{{item.reasonType}}</view>
				</view>
				<view class="content">
					<text class="title">{{$t('homepage.CallDeal.callPeople')}}{{$t('public.colon')}}</text>
					<view class="text">{{item.billUserName}}</view>
				</view>
				<view class="content">
					<text class="title">{{$t('homepage.CallDeal.callReason')}}{{$t('public.colon')}}</text>
					<view class="text">{{item.reasonRemarks}}</view>
				</view>
			</zy-group>
		</view>
		<!-- 底部按钮 -->
		<bottomBtn fixed type="primary" :disabled="disabled" :text="$t('homepage.CallDeal.onReceive')" @btn="submitBtn">
		</bottomBtn>
	</view>
</template>
<script>
	import {
		receiveQuestion
	} from "@/api/homepage.js"
	export default {
		data() {
			return {
				btnList: [{
					text: this.$t('homepage.CallDeal.receive'),
					type: 'warning'
				}],
				disabled:true,
			}
		},
		props: {
			formList: {
				type: Array,
				default: []
			}
		},
		watch:{
			formList:{
				handler(n,o){
					if(n.length>0){
						this.disabled=false
					}else{
						this.disabled=true
					}
				},
				immediate:true,
				deep:true
			}
		},
		methods: {
			// 表单领取
			btnHandle(item, index) {
				this.confirm(item.id)
			},
			// 一键领取
			submitBtn() {
				let idLists = []
				this.formList.map(item => {
					idLists.push(item.id)
				})
				this.confirm(idLists)
			},
			// 弹出层提交领取
			confirm(e) {
				receiveQuestion({
					ids: e,
				}).then((res) => {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 3000
					})
					uni.redirectTo({
						url: "/pages/HomePage/CallDeal/index"
					})
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 3000
					})
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		align-items: center; //上下对齐
		padding: 20rpx;
		width: calc(100% - 40rpx);
	}

	.title {
		color: #999;
		width: 30%;
	}

	.img {
		width: 20rpx;
		height: 20rpx;
	}

	.text {
		text-align: right;
		width: 70%;
	}
</style>